package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.carportWithMap;
import io.swagger.models.auth.In;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TCarport;
import com.ruoyi.system.service.ITCarportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车位管理Controller
 * 
 * @author ruoyi
 * @date 2022-11-29
 */
@RestController
@RequestMapping("/system/carport")
public class TCarportController extends BaseController
{
    @Autowired
    private ITCarportService tCarportService;


    /**
     * 根据Id查询单个数据
     * @param id
     * @return
     */
    @GetMapping("/getcarportWithMap/{id}")
    public carportWithMap getcarportWithMap(@PathVariable("id") Long id){
        carportWithMap carportInfoWithMap = tCarportService.getCarportInfoWithMap(id);
        return carportInfoWithMap;
    }
    
    /**
     * 查询车位名
     * @param
     * @return
     */
    @GetMapping("/carportinfo")
    public TableDataInfo carportInfo(TCarport tCarport){
        List<TCarport> tCarports = tCarportService.selectCarportInfo(tCarport);
        return getDataTable(tCarports);
    }
    
    /**
     * 查询车位管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:carport:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCarport tCarport)
    {
        startPage();
        List<TCarport> list = tCarportService.selectTCarportList(tCarport);
        return getDataTable(list);
    }

    /**
     * 导出车位管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:carport:export')")
    @Log(title = "车位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCarport tCarport)
    {
        List<TCarport> list = tCarportService.selectTCarportList(tCarport);
        ExcelUtil<TCarport> util = new ExcelUtil<TCarport>(TCarport.class);
        util.exportExcel(response, list, "车位管理数据");
    }

    /**
     * 获取车位管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:carport:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tCarportService.selectTCarportById(id));
    }

    /**
     * 新增车位管理
     */
    @PreAuthorize("@ss.hasPermi('system:carport:add')")
    @Log(title = "车位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCarport tCarport)
    {
        return toAjax(tCarportService.insertTCarport(tCarport));
    }

    /**
     * 修改车位管理
     */
    @PreAuthorize("@ss.hasPermi('system:carport:edit')")
    @Log(title = "车位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCarport tCarport)
    {
        return toAjax(tCarportService.updateTCarport(tCarport));
    }

    /**
     * 删除车位管理
     */
    @PreAuthorize("@ss.hasPermi('system:carport:remove')")
    @Log(title = "车位管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tCarportService.deleteTCarportByIds(ids));
    }
}
